package com.xizi.factory.method;

interface Computer {
    public void printComputer();
}

class MacbookProComputer implements Computer {
    public void printComputer() {
        System.out.println("这是一台 macbook pro");
    }
}

class SurfaceBookComputer implements Computer {
    public void printComputer() {
        System.out.println("这是一台 surface book");
    }
}

//创建工厂接口  所有工厂实现这个接口
interface ComputerFactory {
    Computer createComputer();
}

//具体的工厂
class MsFactory implements ComputerFactory {
    public Computer createComputer() {
        return new SurfaceBookComputer();
    }
}

//具体的工厂
class AppleFactory implements ComputerFactory {
    public Computer createComputer() {
        return new MacbookProComputer();
    }
}

//工厂方法模式
public class Client {
    public void buy(Computer c) {
        System.out.println("我想要买一台电脑");
        c.printComputer();
    }

    public static void main(String[] args) {
        Client c = new Client(); //客户
        ComputerFactory cf = new AppleFactory(); //apple工厂
        Computer computer = cf.createComputer(); //多态 创建一台电脑
        c.buy(computer);
    }
}
